package com.Ngbussiness.dao.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.Ngbussiness.dao.dictionaryDao;
import com.Ngbussiness.util.DatabaseAccess;
import com.Ngbussiness.util.EasyMapsManager;


public class dictionaryDaoImpl implements dictionaryDao{
	public JSONArray getprovince(){
             String sql ="select Id,name from dictionary where type=0;";
             try{
                  DatabaseAccess databaseAccess = new DatabaseAccess(false);
                  EasyMapsManager easyMapsManager = new EasyMapsManager(databaseAccess);
                  List list = easyMapsManager.executeQuery(sql);
                  JSONArray json4 = new JSONArray();
                  for(int k=0;k<list.size();k++){
                 	 JSONObject json1=new JSONObject();
                 	 JSONArray json2 = new JSONArray();
                 	 HashMap adu=(HashMap)list.get(k);
                 	 String name=adu.get("name").toString();
                 	 int Id=Integer.parseInt(adu.get("Id").toString());
                 	 System.out.println(name);
                 	 json1.put("first_name", name);
                 	 List list2=new ArrayList();
                 	 String sql2="select name from dictionary where type=?;";
                 	 DatabaseAccess databaseAccess1 = new DatabaseAccess(false);
     				 EasyMapsManager easyMapsManager1 = new EasyMapsManager(databaseAccess1);
     				 easyMapsManager1.setPreparedParameter(Id);
     				 list2=easyMapsManager1.executeQuery(sql2);
     				 for(int j=0;j<list2.size();j++){
     					 HashMap adu1=(HashMap)list2.get(j);
                     	 String name1=adu1.get("name").toString();
                     	 json2.add(name1);
     				 }
     				 json1.put("second_mcid",json2);
     				 json4.add(json1);
                  }
                  databaseAccess.close();
                  return json4;
                 }catch(Exception e) {
                     e.printStackTrace();
                 }
                  return null;
	}
}
